<template>
    <div class="new-project file-info">
        <pui-dialog :maskClick="false" :title="props.title" v-model="componentRef.dialogVisible" :animate="props.animate" isFooter @onCancel="closeDialog">
            <template #content>
                <div class="form">
                    <div class="form-item">
                        <div class="label">项目名称</div>
                        <pui-input placeholder="请输入项目名称" v-model="componentRef.projectName" type="input" clearAble full></pui-input>
                    </div>
                    <div class="form-item">
                        <div class="label">位置</div>
                        <pui-input disabled placeholder="默认路径" v-model="props.directoryPath" type="input" full icon="folder-open" iconPosition="right" @onIconClick="openFolderBrowser"></pui-input>
                    </div>
                </div>
            </template>
            <template #footer>
                <pui-button @click="createNewProject">创建</pui-button>
            </template>
        </pui-dialog>
    </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'NewProject'
})
</script>
<script lang="ts" setup>
import { reactive, getCurrentInstance, watch } from 'vue'
import { projectService as project } from '@/services/phot_client/client'
const { proxy } = getCurrentInstance() as any
const props = defineProps({
    title: {
        type: String,
        default: '新建项目'
    },
    animate: {
        type: String,
        default: 'fade'
    },
    directoryPath: {
        type: String,
        default: ''
    }
})
const emit = defineEmits({
    openFolderBrowser: (val: any) => {},
    onClose: (val: any) => {}
})
const componentRef = reactive({
    dialogVisible: false,
    projectName: '',
    projectType: 0, // 0 系统仿真 1 器件仿真
    address: '默认位置'
})
watch([() => props.directoryPath],(v1) => {
    // console.log(v1)
    componentRef.address = v1[0]
})
const init = () => {
    componentRef.dialogVisible = true
}
const closeDialog = () => {
    componentRef.dialogVisible = false
    emit('onClose', '关闭')
}
const createNewProject = async () => {
    console.log(props.directoryPath, componentRef.projectName, componentRef.projectType)
    await project.newProject(props.directoryPath, componentRef.projectName, componentRef.projectType).then((res: any) => {
        console.log(res)
        closeDialog()
    }).catch((err: any) => {
        console.log(err)
    })
}
const openFolderBrowser = () => {
    
    emit('openFolderBrowser', '浏览文件夹')
}
const getFileAddress = () => {

}
defineExpose({
    init
})
</script>
<style lang="scss">
@import './fileStyle.scss';
</style>